A short description of the post.
To show your figure images in a higher resolution, fix the retina in the above code chunk above.
packages = c('maptools', 'sf', 'raster', 'spatstat', 'tmap', 'tidyverse')
for (p in packages){
if(!require(p, character.only = T)){
install.packages(p)
}
library(p,character.only = T)
}
More on the packages used:
mpsz_sf <- st_read(dsn = "data/shapefile", layer = "MP14_SUBZONE_WEB_PL")
Reading layer `MP14_SUBZONE_WEB_PL' from data source
`C:\aisyahajit2018\IS415\IS415_blog\_posts\2021-09-13-in-class-exercise-5\data\shapefile'
using driver `ESRI Shapefile'
Simple feature collection with 323 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21
We can see from the results above that mpsz_sf projection is in SVY21.
CHAS <- read_rds("data/rds/CHAS.rds")
childcare <- read_rds("data/rds/childcare.rds")
Note: There are some data issue in the childcare data frame because Lat and Lng should be in numeric data type. The coordinate fields are in decimal degrees. Hence, wgs referencing system is assumed.
CHAS_sf <- st_as_sf(CHAS,
coords = c("X_COORDINATE",
"Y_COORDINATE"),
crs=3414)
Note: st_as_sf accepts the coordinates in character data type.
childcare_sf <- st_as_sf(CHAS,
coords = c("Lng",
"Lat"),
crs=4326) %>%
st_transform(crs=3414)
Note: In childcare we have Lng and Lat as the coordinates where they are both in demical degrees. The coordinate system for that is WGS84, crs code 4326. We then use st_transform to change the coordinates of a geometry from one spatial reference system to another.
Notes for arguments: - alpha is to set transparency - col is to set the colour of the dots - size is to set the size of the dots
tmap_mode('view')
tm_shape(childcare_sf) +
tm_dots(alpha=0.4,
col="blue",
size=0.05) +
tm_shape(CHAS_sf) +
tm_dots(alpha=0.4,
col="red",
size=0.05)
tmap_mode('plot')
Note:
The asterisk in Spatial* is to say that we have more than 1 Spatial objects